#include <iostream>

#include "sleep.h"
#include "xgpiops.h"
#include "xparameters.h"

#define GPIO_DEVICE_ID XPAR_XGPIOPS_0_DEVICE_ID

int main() {
  /* Initialize the GPIO driver. */
  // The driver instance for GPIO Device
  XGpioPs Gpio{};
  auto ConfigPtr = XGpioPs_LookupConfig(GPIO_DEVICE_ID);
  XGpioPs_CfgInitialize(&Gpio, ConfigPtr, ConfigPtr->BaseAddr);

  /*  set Pin output,this can control LED */
  /* LED button */
  static u32 PS_LED0{0x07};
  static u32 PS_LED1{0x08};
  /*
   * Set the direction for the pin to be output and
   * Enable the Output enable for the LED Pin.
   */
  XGpioPs_SetDirectionPin(&Gpio, PS_LED0, 1);
  XGpioPs_SetOutputEnablePin(&Gpio, PS_LED0, 1);
  XGpioPs_SetDirectionPin(&Gpio, PS_LED1, 1);
  XGpioPs_SetOutputEnablePin(&Gpio, PS_LED1, 1);

  /* set LED pin value */
  /* Set the GPIO output to be low. */
  while (true) {
    // light on
    XGpioPs_WritePin(&Gpio, PS_LED0, 0x1);
    XGpioPs_WritePin(&Gpio, PS_LED1, 0x1);
    std::cout << "PS LED 0/1 light on" << std::endl;
    sleep(1);

    // light off
    XGpioPs_WritePin(&Gpio, PS_LED0, 0x0);
    XGpioPs_WritePin(&Gpio, PS_LED1, 0x0);
    std::cout << "PS LED 0/1 light off" << std::endl;
    sleep(1);
  }
}
